// See LICENSE for license details.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include "hbird_sdk_soc.h"

#include "insn.h"

void plic_uart0_handler();
void my_uart_init();

static uint8_t count = 0;

int main(void)
{
//	uint32_t baudrate = 16000000;
//	uart_init(UART0, baudrate);
	unsigned int message[8];

	int32_t c,d;
	uint8_t m;
	uint32_t returnCode;
//	returnCode = PLIC_Register_IRQ(PLIC_UART0_IRQn, 1, plic_uart0_handler); /* register system timer interrupt */
//	__enable_irq(); /* enable global interrupt */
//	__enable_minstret_counter();
//	__enable_mcycle_counter();

//	while(1){
//	printf("ZJM Please Enter 256bit message : \r\n");
//	for(int i = 0 ; i < 32 ; i++)
//	{
//		m = uart_read(UART0);
//		message [i/4] = (message[i/4] << 8) | m ;
//	}
//	printf("message[127:0] = %x%x%x%x \r\n",message[3],message[2],message[1],message[0]);
//	printf("message[256:128] = %x%x%x%x \r\n",message[7],message[6],message[5],message[4]);

//	my_uart_init();

	printf("****** Kyber_Coprocessor Start! ******\r\n");

	nice_case(message);
	printf("Success!!!\r\n");

	printf("****** Kyber_Coprocessor End! ******\r\n");

	printf("ASSCC-2023\r\n");

//	while(1)
//	{
//		delay_1ms(100);
//		printf("get %d\r\n",count);
//	}


    return 0;
}

void my_uart_init()
{
	uart_init(UART0,115200);
	uart_config_stopbit(UART0,0);
	uart_disable_paritybit(UART0);
	PLIC_Init(PLIC_UART0_IRQn);
	PLIC_Register_IRQ(PLIC_UART0_IRQn,1,plic_uart0_handler);
	uart_set_rx_th(UART0,0);		//rx中断阈值
	uart_enable_rx_th_int(UART0);	//中断使能

}


void plic_uart0_handler()
{
	uint8_t c;
	count = count + 1;
//	printf("get in");
	//获取8bit字符
	c = uart_read(UART0);

//	printf("get %c",c);
}


